<template>
  <div class="app-container">
    <ht-search-form
      v-show="showSearch"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      defaultEventKey="entryTable"
    ></ht-search-form>
    <ht-table
      ref="dataTable"
      :showSerialNumber="false"
      :multi-select="false"
      :dictMap="dictMap"
      :reqConfig="reqConfig"
      :queryParams="queryParams"
      :opButtonList="opButtonList"
      :tableBindColumns="tableBindColumns"
      defaultEventKey="entryTable"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="center" width="200" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '修改',
                  // permission: 'user:xxx:xxx',
                  doFunc: () => {
                    handleAction('update', scope.row);
                  },
                },
                {
                  label: '明细',
                  // permission: 'user:xxx:xxx',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
                {
                  label: '删除',
                  // permission: 'user:xxx:xxx',
                  doFunc: () => {
                    handleAction('remove', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>
    <edit-info-dialog
      ref="editInfoDialog"
      :form="form"
      :dictMap="dictMap"
      @editComplete="editComplete"
    ></edit-info-dialog>
  </div>
</template>
<script>
import { apiUrlConfig, del } from "@/api/cnaps/tips/FeeItemManage/FeeItemManage.js";
import EditInfoDialog from "./components/FeeItemManageDialog";
import { listPageMixin } from "@/libs/listPageMixin";
export default {
  name: "FeeItemManage",
  mixins: [listPageMixin],
  components: { EditInfoDialog },
  data() {
    return {
      reqConfig: apiUrlConfig,
      //数据字典
      showSearch: true,
      // 查询参数
      queryParams: {
        feeCode: "",
      },
      form: {
        feeCode:"",
        feeCodeDesc:"",
      },
      formOptions: [],
      opButtonList: () => {
        return [
          {
            label: "新增",
            type: "primary",
            clickFun: () => {
              this.handleAction("add");
            },
          },
        ];
      },
      tableBindColumns: [
        { label: `费项代码`, prop: "feeCode", align: "center" },
        {
          label: `费项说明`,
          prop: "feeCodeDesc",
          align: "center",
        },
      ],
    };
  },
  mounted() {
    this.formOptions = [
      {
        type: "input",
        prop: "feeCode",
        defaultAttr: {
          label: "费项代码",
          placeholder: "请输入费项代码",
        },
      },
    ];
  },
  methods: {
    editComplete(state) {
      if (state == true) {
        this.$refs.dataTable.doQuery();
      }
    },
    /***
     * 按钮操作汇总
     */
    handleAction(type, row) {
      switch (type) {
        case "add":
          this.form.title = "费项新增";
          this.form.isDetail = true;
          this.form.disabled = false;
          this.form.isDisabled = false;
          this.$refs.editInfoDialog.show();
          break;
        case "update":
          this.form = _.clone(row);
          this.form.title = "费项修改";
          this.form.isDetail = true;
          this.form.disabled = false;
          this.form.isDisabled = true;
          this.$refs.editInfoDialog.show(_.clone(row));
          break;
        case "detail":
          this.form = _.clone(row);
          this.form.title = "费项明细";
          this.form.isDetail = false;
          this.form.disabled = true;
          this.form.isDisabled = true;
          this.$refs.editInfoDialog.show();
          break;
        case "remove":
          this.$confirm("是否删除这条数据？", "系统提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            del(row).then(() => {
              this.msgSuccess("操作成功！");
            });
          });
          break;
      }
    },
  },
};
</script>
